19. Exercise: Add Firebase to your Project
L1 A19 Add Firebase To Your Project
Resources
- Firebase console
- Firebase Android config file
- google-services plugin
- Starter code repository (Check out the
startbranch) Exercise
Step 1: Create a Firebase project
Before you can add Firebase to your Android app, you need to create a Firebase project to connect to your Android app.
After logging in to the Firebase console, click Add project, then select or enter a Project name. Name your project ‘fcm-codelab’.
Click Continue.
You can skip setting up Google Analytics and choose the ‘Not Right Now’ option.
Click ‘Create Project’ to finish setting up the Firebase project.
Step 2: Register your app with Firebase
Now that you have a Firebase project, you can add your Android app to it.
In the center of the Firebase console's project overview page, click the Android icon to launch the setup workflow.
Enter the package id of your android project,
com.example.android.eggtimernotifications, as the Firebase application Id. Make sure you enter the ID your app is using because you cannot add or modify this value after you’ve registered your app with your Firebase project.Click Register app.
Step 3: Add the Firebase configuration file to your project
Add the Firebase Android configuration file to your app:
Click Download google-services.json to obtain your Firebase Android config file (
google-services.json).- You can download your Firebase Android config file again at any time.
- Make sure the config file is not appended with additional characters and should only be named
google-services.json
Move your config file into the module (app-level) directory of your app.
Step 4: Configure your Android project to enable Firebase products
To enable Firebase products in your app, add the google-services plugin to your Gradle files.
In your (project-level) Gradle file (
build.gradle), add rules to include the Google Services plugin. Check that you have Google's Maven repository, as well.
build.gradle
buildscript {
repositories {
// Check that you have the following line (if not, add it):
google() // Google's Maven repository
}
dependencies {
// ...
// Add the following line:
classpath 'com.google.gms:google-services:4.3.0' // Google Services plugin
}
}
allprojects {
// ...
repositories {
// Check that you have the following line (if not, add it):
google() // Google's Maven repository
// ...
}
}
- In your app-level Gradle file (usually
app/build.gradle), add a line to the bottom of the file.
app/build.gradle
apply plugin: 'com.android.application'
android {
// ...
}
// Add the following line to the bottom of the file:
apply plugin: 'com.google.gms.google-services' // Google Play services Gradle plugin
- Since the gradle files are changed, perform a gradle sync.